package com.gt.exception;

import com.gt.common.AjaxResult;
import com.gt.common.HttpStatus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author hl
 * @Data 2020/7/20
 * <p>
 * 集中处理所有异常
 */
@Slf4j
@RestControllerAdvice(basePackages = "com.gt.self.controller")
public class SelfServiceExceptionController {

    @ExceptionHandler(value = {SelfServiceException.class})
    public AjaxResult handleValidException(SelfServiceException e) {
        e.printStackTrace();
        return AjaxResult.error(e.getCode(), e.getMessage());
    }

    @ExceptionHandler(value = {Exception.class})
    public AjaxResult handleException(Exception e) {
        log.error("系统异常，异常消息：{},异常类型：{}", e.getMessage(), e.getClass());
        e.printStackTrace();
        return AjaxResult.error(HttpStatus.ERROR, e.getMessage());
    }
}
